package com.bawei.room;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/15 09:11
 * @Description : StudentDao
 */
//2：dao层：增删改查
@Dao
public interface StudentDao {
    //插入一条数据:id冲突的时候替换为新的
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(Student student);
    //插入多条数据:id冲突的时候替换为新的
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(List<Student> students);

    //删除一条数据
    @Delete
    void delete(Student student);
    //删除多条数据
    @Delete
    void delete(List<Student> students);
    //删除全部数据
    @Query("delete from student")
    void deleteAll();


    //修改数据
    @Update
    void update(Student student);
    //查询所有数据 按照年龄倒序排序
    @Query("select * from student order by age desc")
    List<Student> getAllStudents();
    //条件查询:模糊查询
    @Query("select * from student where username like '%'||:username||'%' ")
    List<Student> getStudentByName(String username);


}
